package com.atguigu.jxc.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.jxc.dao.PurchaseListDao;
import com.atguigu.jxc.dao.PurchaseListGoodsDao;
import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.entity.PurchaseListGoods;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.SupplierService;
import com.atguigu.jxc.util.AuthContextHolder;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    @Override
    public Map<String, Object> list(Integer page, Integer rows, String supplierName) {
        //开启分页
        PageHelper.startPage(page,rows);
        //执行dao
        Page<Supplier> supplierPage =supplierDao.listSelect(supplierName);
        Map<String, Object> map=new HashMap<>();
        map.put("rows",supplierPage);
        map.put("total",supplierPage.getTotal());
        return map;
    }


    //    供应商添加或修改
    @Override
    public void saveSupplier(Supplier supplier,String supplierId) {
//        String supplierId = request.getParameter("supplierId");
        if (supplierId!=null){
            //修改
//            Map<String, Object> map = new HashMap<>();
//            map.put("supplier",supplier);
//            map.put("supplierId",supplierId);
            supplierDao.updateSupplier(supplier);
        }else {
            //新增
            supplierDao.saveSupplier(supplier);
        }
    }

    //批量删除
    @Override
    public void delete(String[] ids) {
        if (ids.length>0||ids!=null) {
            //遍历id
            for (String id : ids) {
                supplierDao.deleteSupplier(id);
            }
        }
    }

    //供应商下拉列表查询 String q（供应商名称模糊查询）
    @Override
    public List<Supplier> getComboboxList(String q) {
        return supplierDao.getComboboxList(q);
    }


}
